package com.jiudaoliu.homeprototype.controller;

import com.jiudaoliu.homeprototype.POJO.VO.CommonVO;
import com.jiudaoliu.homeprototype.enums.STATUS_ENUM;
import com.jiudaoliu.homeprototype.service.ModelService;
import com.jiudaoliu.homeprototype.utils.CommonVO_Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Package com.jiudaoliu.homeprototype.controller
 * @Description:
 * @Author 陈建
 * @Create: 2018-09-21 09:25
 * @Version 1.0
 * @Update: message
 */
@RestController
@RequestMapping(value = "/model")
public class ModelController {

    @Autowired
    private ModelService modelServiceImpl;

    @PostMapping(value = "/ceshishuju")
    public CommonVO ceshishuju() {
        System.out.println("ok");
        return CommonVO_Utils.success();
    }

    /**
     * @Description: 根据状态查询, 默认查询正在使用中的模块
     * @Param: [status:状态]
     * @Return: com.jiudaoliu.homeprototype.POJO.VO.CommonVO
     * @Author: 陈建
     * @date: 2018/9/21 9:28
     */
    @GetMapping(value = "/find/{status}")
    public CommonVO getModels(@PathVariable String status) {
        if (null != status && STATUS_ENUM.STATUS_ALL.getStatus().equals(status)) {
            //匹配all,查询所有
            return modelServiceImpl.findAll();
        } else {
            return modelServiceImpl.findAllByStatus(STATUS_ENUM.STATUS_USE.getStatus());
        }
    }

    @GetMapping(value = "/findone/{id}")
    public CommonVO findById(@PathVariable Long id) {
        return modelServiceImpl.findById(id);
    }
}
